package com.glsc.ngateway.common.base.repo.mysql.gateway.platform.it.networkAssets;

import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.networkassets.RateExceptionExclude;
import com.glsc.ngateway.common.api.platform.dto.it.networkassets.RateExceptionExcludeDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotNull;
import java.util.List;

@Repository
public interface RateExceptionExcludeRepo extends JpaRepository<RateExceptionExclude, Long> {

    @Query(value = "select * from t_gw_it_net_assets_rate_exception h " +
            "where deleted = 0 " +
            "and if( :#{#rateExpExlDto.host} is not null, h.host like CONCAT('%', :#{#rateExpExlDto.host}, '%'), 1=1) " +
            "and if( :#{#rateExpExlDto.ifName} is not null, h.if_name like CONCAT('%', :#{#rateExpExlDto.ifName}, '%'), 1=1) " +
            "and if( :#{#rateExpExlDto.referenceSpeed} is not null, h.reference_speed like CONCAT('%', :#{#rateExpExlDto.referenceSpeed}, '%'), 1=1) " +
            "and if( :#{#rateExpExlDto.description} is not null, h.description like CONCAT('%', :#{#rateExpExlDto.description}, '%'), 1=1) " +
            "", nativeQuery = true)
    Page<RateExceptionExclude> page(Pageable pageable, @NotNull @Param("rateExpExlDto") RateExceptionExcludeDto param);

    @Query(value = "select * from t_gw_it_net_assets_rate_exception h " +
            "where deleted = 0 " +
            "and if( :#{#rateExpExlDto.host} is not null, h.host like CONCAT('%', :#{#rateExpExlDto.host}, '%'), 1=1) " +
            "and if( :#{#rateExpExlDto.ifName} is not null, h.if_name like CONCAT('%', :#{#rateExpExlDto.ifName}, '%'), 1=1) " +
            "and if( :#{#rateExpExlDto.referenceSpeed} is not null, h.reference_speed like CONCAT('%', :#{#rateExpExlDto.referenceSpeed}, '%'), 1=1) " +
            "and if( :#{#rateExpExlDto.description} is not null, h.description like CONCAT('%', :#{#rateExpExlDto.description}, '%'), 1=1) " +
            "", nativeQuery = true)
    List<RateExceptionExclude> queryAll(@NotNull @Param("rateExpExlDto")RateExceptionExcludeDto param);
}
